var signProjectStore = null;
var gridStoresn = null;
Ext.define('component.marketing.signingPanel', {
	extend : 'Ext.form.Panel',
	initComponent:function(){
		
		//项目
		signProjectStore = new Ext.data.Store({
	        singleton:true,
	        autoDestroy:true,
	        fields: ["id", "projectName"],
	        proxy:{
	            type:'ajax',
	            url:contextPath+'/estate/project/findProjectList?resourcesCode=menu_0003_0001',
	            reader:{
                   type: 'json', 
                   root: 'root'  //数据
              }
	        } ,
	        autoLoad: false
		});
		signProjectStore.load({
			callback:function(records, options, success){
				var count = signProjectStore.getCount();
				if(count>0){
					var id = signProjectStore.getAt(0).get("id");
					Ext.getCmp('signProjectStore').setValue(id)
				}
				if(Ext.Array.contains(idata,"marketing:list:all")){
					var data = {"projectName": "全部", "id": '-1'};
					var rs = Ext.create(data);
					signProjectStore.insert(count+1, rs);
				}
			}
		});
		
		var formsn = Ext.create("Ext.form.Panel", {
			minHeight:170,
		    title: "查询条件",
		    collapsible: true,  //可折叠
		    autoScroll: false,   //自动创建滚动条
		    defaultType: 'textfield',
		    defaults: {
		    	 anchor: '100%'
		    },
		    fieldDefaults: {
		        margin: 2,
		        labelWidth: 80,
		        labelAlign: "right",
	            margin: "5 0 0 0"
		    },
		    items: [
	            {
				    xtype: "container",
				    layout: "hbox",
				    items: [{
					    xtype: "container",
					    layout: "hbox",
					    items: [{  
					            xtype:'combobox',
					            id:'signProjectStore',
					            name: "projectId",
					            store: signProjectStore,
					            valueField: "id",  
					            displayField: "projectName",
					            fieldLabel:'所属项目',
					            queryMode:'local',
					            typeAhead: true,
					            editable: false
					        },{
					        	xtype: "textfield",
					        	name:"customerName",
					        	fieldLabel: "客户名称"
					        }
			        	]
					}]
				},{
		            xtype: "container",
		            layout: "hbox",
		            items: [{
		            		xtype:"textfield", name:"resourcesCode",
		            		value: resourcesCode, hidden: true
						},{
							xtype:"textfield", name:"resourcesName",
							value: "resName_pin_list", hidden: true
						},{
				        	xtype: "textfield",
				        	name:"mobile",
				        	fieldLabel: "客户电话"
				        },{
				        	xtype: "textfield",
				        	name:"agentName",
				        	fieldLabel: "经纪人"
				        },{  
    			            fieldLabel:"逾期未付款",  
    			            xtype:"combo", 
    			            name:"isOverdue",
    			            displayField: 'name',
    			            valueField: 'value',
    			            mode:"local",  
    			            store:new Ext.data.Store({  
    			                fields: ['value', 'name'],
    			                data : [
    			                    {"value":"", "name":"全部"},
    			                    {"value":">", "name":"是"},
    			                    {"value":"<=", "name":"否"}
    			                ] 
    			            })  
    			        }
		            ]
		        },{
					xtype: "container",
					layout: "hbox",
					items: [
						{
							xtype: "textfield",
							name:"combinedName",
							fieldLabel: "房号"
						},
						{ xtype: "datefield", name: "didTimeBefore",fieldLabel: "签约日期",format:'Y-m-d'},
		                {margin: "0 5 0 5",xtype: 'displayfield',value:'-'},
		                { xtype: "datefield", name: "didTimeAfter", format:'Y-m-d'}
					]
				},{
		            xtype: "container",
		            layout: "hbox",
		            items: [{ 
    	            	xtype: "checkboxgroup",
    	            	id:"ckStatuSn",
    	            	name:"m_auditStatus",
    	            	fieldLabel: "审核状态",
		            	width:450,
    	            	items:[{
        	            		boxLabel:'待提交',
        	            		inputValue:'0'
        	            	},{
        	            		boxLabel:'审核中',
        	            		inputValue:'1'
        	            	},{
        	            		boxLabel:'已通过',
        	            		inputValue:'3',
        	            		checked: true
        	            	},{
        	            		boxLabel:'已退回',
        	            		inputValue:'2'
        	            	}
    	            	]}
		            ]
	            },{
	                xtype: 'fieldset',
	                title: '更多...',
	                collapsible: true,
	                collapsed :true,
	                defaults: {
	                    labelWidth: 89,
	                    anchor: '100%',
	                    layout: {
	                        type: 'hbox',
	                        defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
	                    }
	                },
	                items: [{
	    			    xtype: "container",
	    			    layout: "hbox",
	    			    items: [
	    					{xtype:"textfield", name:"resourcesCode", value: resourcesCode, hidden: true},
	    					{xtype:"textfield", name:"resourcesName", value: "resName_pin_list", hidden: true},
	    			        { xtype: "textfield", name: "signCode", fieldLabel: "签约编号" },
	    			        {  
		                        fieldLabel:"付款方式",  
		                        xtype:"combo", 
		                        name:"paymentMethod",
		                        displayField: 'name',
		                        valueField: 'value',
		                        /* 从本地加载数据 */  
		                        mode:"local",  
		                        store:new Ext.data.Store({  
			                        	fields: ['value', 'name'],
			                            data : [
			                                {"value":"1", "name":"一次性贷款"},
			                                {"value":"3", "name":"商业贷款"},
			                                {"value":"4", "name":"公积金贷款"},
			                                {"value":"2", "name":"分期付款"},
			                                {"value":"5", "name":"组合贷款"}
			                            ] 
		                            })  
		                    },
		                    {  
		                        fieldLabel:"是否精装修",  
		                        xtype:"combo", 
		                        name:"isDecoration",
		                        displayField: 'name',
		                        valueField: 'value',
		                        /* 从本地加载数据 */  
		                        mode:"local",  
		                        store:new Ext.data.Store({  
			                        	fields: ['value', 'name'],
			                            data : [
			                            	{"value":"","name":"全部"},
			                            	{"value":"1","name":"是"},
			                            	{"value":"2","name":"否"}
			                            ] 
		                            })  
		                    }
	    			    ]},{
	    					xtype: "container",
	    				    layout: "hbox",
	    				    items: [
	    				        { xtype: "datefield", name: "checkDateBefore", fieldLabel: "审核日期",format:'Y-m-d'},
								{margin: "0 5 0 5",xtype: 'displayfield',value:'-'},
								{ xtype: "datefield", name: "checkDateAfter", format:'Y-m-d'}
	    				    ]
	    				},{
	    				    xtype: "container",
	    				    layout: "hbox",
	    				    items: [{ 
								xtype: "checkboxgroup",
				            	id:"busStatuSn",
				            	fieldLabel: "业务状态",
				            	name :"m_businessStatus",
				            	width:450,
				            	items:[{
					            		boxLabel:'签约',
					            		inputValue:'1'
					            	},{
					            		boxLabel:'已退房',
					            		inputValue:'2'
					            	},{
					            		boxLabel:'已换房',
					            		inputValue:'3'
					            	},{
					            		boxLabel:'已更名',
					            		inputValue:'4'
					            	}
				                 ]
			            	}]
	    				}]
	            }
	        ],
		    buttons: [
				  	        { xtype: "button", text: "查询", handler:function(){
				  	        		//获取通过checkboxgroup定义的checkbox值
				  	        		//审核状态
				  	        		var ckStatusValue = Ext.getCmp('ckStatuSn').getChecked();
				  	        		var ckStatus="";
				  	        		Ext.Array.each(ckStatusValue, function(item){
				  	        			ckStatus += item.inputValue+',' ;
				  	        		});
				  	        		gridStoresn.getProxy().extraParams.m_auditStatus = ckStatus;
				  	        		//业务状态
				  	        		var busStatusValue = Ext.getCmp('busStatuSn').getChecked();
				  	        		var busStatus="";
				  	        		Ext.Array.each(busStatusValue, function(item){
				  	        			busStatus += item.inputValue+',' ;
				  	        		});
				  	        		gridStoresn.getProxy().extraParams.m_businessStatus = busStatus;
				  	        		gridStoresn.load();
				  	        		var pagingTool=Ext.getCmp("pagingToolq");
				  	        		pagingTool.moveFirst();//跳至第一页
				  	        	}  
				  	        },
				  	        { xtype: "button", text: "清空",handler:function(){
				  	        		formsn.getForm().reset();
				  	        	}
				  	        },{
								xtype : "button",
								text : "批量导入",
								hidden: true,
								handler : function() {
									var selectProjectId = Ext.getCmp(
											"signProjectStore").getValue();
									if (selectProjectId
											&& selectProjectId == "-1") {
										Ext.MessageBox.alert("系统提示",
												"请选择项目");
										return;
									}
									signedImport();
								}
							},{
				  	        	xtype:"button",text:"导出",hidden:sigDataExport,handler:function(){
				  	        		var count = gridsn.getStore().getCount();
				  	        		if(count<=0){
				  	        			 Ext.MessageBox.alert("系统提示","没有可导出的数据"); 
				  	        		}else{
				  	        			var ckStatusValue = Ext.getCmp('ckStatuSn').getChecked();
					  	        		var ckStatus="";
					  	        		Ext.Array.each(ckStatusValue, function(item){
					  	        			ckStatus += item.inputValue+',' ;
					  	        		});
					  	        		gridStoresn.getProxy().extraParams.m_auditStatus = ckStatus;
					  	        		//业务状态
					  	        		var busStatusValue = Ext.getCmp('busStatuSn').getChecked();
					  	        		var busStatus="";
					  	        		Ext.Array.each(busStatusValue, function(item){
					  	        			busStatus += item.inputValue+',' ;
					  	        		});
					  	        		gridStoresn.getProxy().extraParams.m_businessStatus = busStatus;
					  	        		var value = encodeURI(encodeURI(JSON.stringify(gridStoresn.getProxy().extraParams),"utf-8"));
					  	        		location.href=jypath+'/customer/signed/signedInfoExport?value='+value;
				  	        		}
				  	        		
				  	        	}
				  	        }
				  	    ]    
	});
		
	var statistics = Ext.create('Ext.form.FormPanel',{
		items:[{
            xtype: "fieldcontainer",
            layout: "hbox",
            items: [
            	{xtype: "fieldcontainer", layout: "column",
    				items:[
    				    {xtype: "displayfield", value: "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共"},
	    				{xtype: "displayfield", name: "info_sumRoom", value:"0"},
	    				{xtype: "displayfield", value: "套,&nbsp;&nbsp;&nbsp; "}
    				]
				},
				{xtype: "fieldcontainer", layout: "column",
    				items:[
	    				{xtype: "displayfield", name: "info_calculateArea", value:"0"},
	    				{xtype: "displayfield", value: "㎡,&nbsp;&nbsp;&nbsp; "},
    				]
				},
				{xtype: "fieldcontainer", layout: "column",
    				items:[
	    				{xtype: "displayfield", name: "info_Amount", value:"0", renderer: Ext.util.Format.numberRenderer('0,000.00')},
	    				{xtype: "displayfield", value: "元"},
    				]
				}
            ]
		}]
	});
	
	gridStoresn = Ext.create('Ext.data.Store', {
        fields: ["id","didTime","customerName", "combinedName"
                 , "roomStatus","houseTypeName","calculateArea"
                 ,"signPrice","signAmount","paymentMethod","totalRealAmount","userName"
                 ,"businessStatus" , "auditStatus","roomId", "overdueDay", "overdueAmount", "receivables", "decorationMoney"],
        pageSize: 10,  //页容量5条数据
        //是否在服务端排序 （true的话，在客户端就不能排序）
        remoteSort: false,
        proxy: {
            type: 'ajax',
            url: jypath+'/customer/signed/list',
            actionMethods: { read: 'POST' },
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows',  //数据
                totalProperty: 'total' //数据总条数
            },
            extraParams:{
            	isStatusTrue:'1' //用于判断是否显示换房、退房数据（isStatusTrue不为null为不显示）
            }
        },
        autoLoad: true  //即时加载数据
    });
	
	gridStoresn.on("beforeload",function(){
        Ext.apply(gridStoresn.proxy.extraParams,formsn.getForm().getValues());
        var projectId = Ext.getCmp("signProjectStore").getValue();
		gridStoresn.proxy.extraParams.projectId = projectId;
        if(projectId == "-1"){
        	gridStoresn.proxy.extraParams.projectId = "";
        }
        var m_auditStatus = gridStoresn.getProxy().extraParams.m_auditStatus;
        if(!m_auditStatus){
        	gridStoresn.getProxy().extraParams.m_auditStatus = "3";
        }
		var newResCode = resourcesCode;
		if(resourcesCode != "menu_0005_0005"){
			newResCode = resourcesCode + ",menu_0005_0005";
		}
        gridStoresn.proxy.extraParams.resourcesCode = newResCode;
        
    });
	
	Math.formatFloat = function(f, digit) { 
	    var m = Math.pow(100, digit); 
	    return parseInt(f * m, 10) / m; 
	} 
	gridStoresn.on("load",function(){
		var signAmount = 0;
		var calculateArea = 0;
		var rows = gridStoresn.getCount();
		for(var i = 0; i < rows; i++){
			var rowData = gridStoresn.getAt(i).data;
			calculateArea += rowData.calculateArea;
			signAmount += rowData.signAmount;
		}
		statistics.getForm().findField("info_sumRoom").setValue(rows);
		statistics.getForm().findField("info_calculateArea").setValue(Math.formatFloat(calculateArea, 1));
		statistics.getForm().findField("info_Amount").setValue(Math.formatFloat(signAmount, 1));
    });
	
//	function onreload(){
//		gridStoresn.on("beforeload",function(){
//	        Ext.apply(gridStoresn.proxy.extraParams,formsn.getForm().getValues());
//	    });
//	}
	
	var gridsn = Ext.create('Ext.grid.Panel', {
		minHeight:600,
        store: gridStoresn,
        columnLines: true,
        
        columns: [{  
        	text : "操作",
        	width: 250,
            dataIndex: 'actioncolumn',
            locked   : true,
            renderer: function(value,cellmeta,record,rowIndex,columnIndex,store) {
                var rec = gridsn.getStore().getAt(rowIndex);
//         		if(rec.get('auditStatus') == 0){
//                	return html = "<a href='"+jypath+"/customer/signed/toView?id="+rec.get('id')+"&returnUrl=,marketing,pin,index' style='cursor:pointer'>查看</a>"
//                				+"&emsp;<a href='javascript:del("+rec.get('id')+")'>删除</a>";
//         		}
                //查看
                 var tabKey = "sig_"+rec.get('id');
                 
                 var html = "<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"签约详情\",\"/customer/signed/toView?id="+rec.get('id')+"&returnUrl=,marketing,pin,index\")' style='cursor:pointer'>查看</a>";
                 if(rec.get('auditStatus')==0 || rec.get('auditStatus')==2){
                 	//房间为签约状态，可编辑
                 	if(rec.get("roomStatus") == 5 || rec.get("roomStatus") == 1 || rec.get("roomStatus") == 4){
                 		var tabKey = "sub_to_sig_"+rec.get('id');
                 		html+="&emsp;<a href='javascript:parent.openMenu(\"0\",\""+tabKey+"\",\"\",\"签约编辑\",\"/customer/signed/toEdit?id="+rec.get('id')+"&returnUrl=,marketing,pin,index\")' style='cursor:pointer'>编辑</a>";
                 	}
                 	//审核状态为待提交时，可编辑
                 	if(rec.get('auditStatus')==0){
                 		html += "&emsp;<a href='javascript:delSigning("+rec.get('id')+")'>删除</a>";
                 	}
                 	return html;
                 }
                 
                 var timeStr = Ext.Date.format(new Date(rec.get('didTime')),'Y-m-d');
                 
               /*  html+="&emsp;<a href='javascript:signedDeleteHotfix("+rec.get('id')+")'>修正删除</a>";*/
                 if(!dataRepairSigneDate){
                	 html+="&emsp;<a href='javascript:correct(\""+timeStr+ "\","+rec.get('id')+")'>签约日期变更</a>";
                 }
                 
                 var signeId=rec.get('id');
                 var paymentMethod=rec.get('paymentMethod');
                 var signAmount=rec.get('signAmount');
 	    	     var customerName=rec.get('customerName');
 	    	     var roomName=rec.get('combinedName');
 	    	    
 	    	     if(!dataRepairSigneInfo){
 	                html += "&emsp;<a href='javascript:signeAmountRepairData("+signeId+",&apos;"+paymentMethod+"&apos;,"+signAmount+",&apos;"+customerName+"&apos;,&apos;"+roomName+"&apos;)'>合同信息变更</a>";
 	    	     }
                 return html;
            }
        },{
            text: '签约日期',
            dataIndex: 'didTime',
            renderer:function(value){
            	return Ext.Date.format(new Date(value),'Y-m-d')
            }
        },{
            text     : '客户名称', 
            dataIndex: 'customerName'
        },{
            text     : '房号',
            dataIndex: 'combinedName',
            width:250,
            renderer: function(value,cellmeta,record,rowIndex,columnIndex,store) {
           	 var rec = gridsn.getStore().getAt(rowIndex);
              	 var roomId = rec.get('roomId');
              	 if(roomId!=null){
              		 return "<a style='text-decoration:none;' href='javascript:openWindow("+roomId+")'>"+value+"</a>";
              	 }
          	 return value;
          }
        },{
            text     : '户型',
            dataIndex: 'houseTypeName',
            renderer : function(val) {
                if (val == 0) {
                    return '正常';
                } else if (val == 1) {
                    return '已关闭';
                }
                return val;
            }
        },{
            text     : '计价面积(平方米)',
            dataIndex: 'calculateArea'
        },{
            text     : '签约单价(元)',
            dataIndex: 'signPrice', renderer: Ext.util.Format.numberRenderer('0,000.00')
        },{
            text     : '合同金额(元)',
            dataIndex: 'signAmount', renderer: Ext.util.Format.numberRenderer('0,000.00')
        },{
            text     : '装修款(元)',
            dataIndex: 'decorationMoney',
            renderer:function(value){
            	if(value==null||value==""){
            		return "0.00";
            	}
            	return Ext.util.Format.number(value,'0,000.00');
            }
        },{
            text     : '付款方式',
            dataIndex: 'paymentMethod',
            renderer : function(val) {
                if (val == 1) {
                    return '一次性付款';
                } else if (val == 2) {
                    return '分期付款';
                }else if (val == 3) {
                    return '商业按揭';
                }else if (val == 4) {
                    return '公积金按揭';
                }else if (val == 5) {
                    return '组合贷款';
                }
                return val;
            }
        },{
            text     : '未收款(元)',
            dataIndex: 'receivables',
            renderer:function(value){
            	if(value==null||value==""){
            		return "0.00";
            	}
            	return Ext.util.Format.number(value,'0,000.00');
            }
        },{
            text     : '已收金额(元)',
            dataIndex: 'totalRealAmount',
            renderer:function(value){
            	if(value==null||value==""){
            		return "0.00";
            	}
            	return Ext.util.Format.number(value,'0,000.00');
            }
        },{
            text     : '是否逾期未付款',
            dataIndex: 'overdueDay',
            renderer : function(val) {
                if (val > 0) {
                    return '是';
                } else {
                    return '否';
                }
            }
        },{
            text     : '逾期天数',
            dataIndex: 'overdueDay',
            renderer : function(val) {
                if (val > 0) {
                    return val;
                } else {
                    return '';
                }
            }
        },{
            text     : '逾期未付款金额(元)',
            dataIndex: 'overdueAmount',
            renderer:function(value){
            	if(value==null||value==""){
            		return "0.00";
            	}
            	return Ext.util.Format.number(value,'0,000.00');
            }
        },{
            text     : '经纪人',
            dataIndex: 'userName'
        },{
            text     : '业务状态',
            dataIndex: 'businessStatus',
            renderer : function(val) {
                if (val == 1) {
                    return '签约';
                } else if (val == 2) {
                    return '已退房';
                }else if (val == 3) {
                    return '已换房';
                }else if (val == 4) {
                    return '已更名';
                }
                return val;
            }
        },{
            text     : '审核状态',
            dataIndex: 'auditStatus',
            renderer : function(val) {
                if (val == 0) {
                    return '待提交';
                } else if (val == 1) {
                    return '审核中';
                }else if (val == 3) {
                    return '已通过';
                }else if (val == 2) {
                    return '已退回';
                }
                return val;
            }
        }],
        title: '签约列表',
        dockedItems: [{  
            xtype: 'pagingtoolbar',  
            store: gridStoresn,   // GridPanel中使用的数据  
            dock: 'bottom',  
            displayInfo: true,  
            emptyMsg:"没有数据",  
            displayMsg:"显示从{0}条数据到{1}条数据，共{2}条数据",
            id:'pagingToolq'
        }
        ]
    });
	
		
		var defaultConfigg = {
				defaults: {  
		            split: true,    //有分割线  
		            collapsible: true  //可以折叠
		        },
				items:[formsn, statistics, gridsn]
		};
		Ext.apply(this,defaultConfigg);
		this.callParent(arguments);
		
	}
});


function correct(sigDate,id){
	
	var fromPanel =   Ext.create("Ext.form.Panel", {
			collapsible : false, 
			autoScroll : false, 
			defaultType : 'textfield',
			defaults : {
				anchor : '100%'
			},
			fieldDefaults : {
				flex : 1
			},	
			items : [{
				xtype: "datefield",
				fieldLabel: "签约日期",
				format:'Y-m-d',
				id:'newSigTimeValue',
	            value:sigDate
  		     }]
	});
	
	var window = Ext.create('Ext.Window', {
		   title: "修正数据",
	        width: 300,
	        closable: true,
	        modal : true,
	        headerPosition: 'top',
	        items: [fromPanel],
	        buttons:[{
	        	xtype: "button",
	        	text: "确定",
	        	iconCls:'icon-save',
	        	handler: function(){
	        		
	        		var newSigTime = Ext.Date.format(new Date(Ext.getCmp("newSigTimeValue").getValue()),'Y-m-d');
	        		Ext.Ajax.request({
	        			 url: jypath+'/hoxfit/updateSignedDate',
	                     params: { sigId:id,sigDate:newSigTime},
	                     method: 'POST',
	                     callback: function (options, success, response) {
	                    	 if (success) {
	                    		 var obj = eval('(' + response.responseText + ')');
	                    		 if(obj.res=="1"){
	                    			 Ext.MessageBox.alert("系统提示","修正签约记录成功");
	                    			 gridStoresn.load();
	                    		 }else if(obj.res=="100"){
	                    			 Ext.MessageBox.alert("系统提示","该账号没有修复权限");
	                    		 }
	                    		 window.close();
	                    	 }else{
	                    		 Ext.MessageBox.alert("系统提示","修正签约记录失败！");
	                    	 }
	                     }
	        		});
	        		
	        	}
	        }]
	       
	});
	window.show();
}

function delSigning(id){
    Ext.MessageBox.confirm("提示","是否删除该签约记录?",function(btn,txt){
    	if(btn=="yes"){
    		Ext.Ajax.request({
    			 url: jypath+'/customer/signed/delete',
                 params: { id: id},
                 method: 'POST',
                 callback: function (options, success, response) {
                	 if (success) {
                		 var obj = eval('(' + response.responseText + ')');
                		 if(obj.res == '100'){
                			 Ext.MessageBox.alert("系统提示","该账号没有删除权限");
                		 }else{
                			 Ext.MessageBox.alert("系统提示","删除签约记录成功");
                			 gridStoresn.load();
                		 }
                	 }else{
                		 Ext.MessageBox.alert("系统提示","删除签约记录失败！");
                	 }
                 }
    		});
        }
    });
}



/*function signedDeleteHotfix(id){
    Ext.MessageBox.confirm("提示","是否删除该签约记录?",function(btn,txt){
    	if(btn=="yes"){
    		Ext.Ajax.request({
    			 url: jypath+'/hoxfit/signedDeleteHotfix',
                 params: { id: id},
                 method: 'POST',
                 callback: function (options, success, response) {
                	 if (success) {
                		 var obj = eval('(' + response.responseText + ')');
                		 if(obj.res == '100'){
                			 Ext.MessageBox.alert("系统提示","该账号没有删除权限");
                		 }else{
                			 Ext.MessageBox.alert("系统提示","删除签约记录成功");
                			 gridStoresn.load();
                		 }
                	 }else{
                		 Ext.MessageBox.alert("系统提示","删除签约记录失败！");
                	 }
                 }
    		});
        }
    });
}*/

function signeAmountRepairData(id,paymentMethod,signAmount,customerName,roomName){
	    var selectWindow=Ext.create('component.repairData.signeAmount',{
	    	    customerName:customerName,
	    	    roomName:roomName,
	 	    	paymentMethod: paymentMethod,
	 	    	signAmount: signAmount,
	 	    	signedId: id,
	 	    	modal: true,
	 	    	callbackFun:function(){
	 	    		gridStoresn.load();
	 	    	}
	 	 });
	 	 selectWindow.show();

}

function signedImport(){
	var fromPanel = Ext.create("Ext.form.Panel", {
		collapsible : false,
		autoScroll : false,
		defaultType : 'textfield',
		defaults : {
			anchor : '100%'
		},
		fieldDefaults : {
			flex : 1
		},
		items : [{
			xtype : 'filefield',
			fieldLabel : '导入excel',
			emptyText : '请上传excel文件',
			id : 'multipartFile',
			name : 'multipartFile',
			msgTarget : 'side',
			allowBlank : false,
			anchor : '95%',
			buttonConfig : {
				iconCls : 'silk-folder'
			},
			buttonText : '选择文件'
		}]
	});

	var window = Ext.create('Ext.Window', {
		title: "批量导入",
		width: 300,
		height: 150,
		closable: true,
		modal: true,
		headerPosition: 'top',
		items: [fromPanel],
		buttons: [{
			xtype: "button",
			text: "开始导入",
			iconCls: 'icon-save',
			handler: function() {
				var form = fromPanel.getForm();
				var selectProjectId = Ext.getCmp("signProjectStore").getValue();
				if (selectProjectId == "") {
					Ext.MessageBox.alert("系统提示", "请选择项目");
					return;
				}
				if (form.isValid()) {
					var params = form.getValues();
					params.projectId = selectProjectId;
					form.submit({
						url: contextPath + '/marketing/import/signedImport',
						params: params,
						method: "POST",
						waitMsg: '正在上传...',
						success: function(form, action) {
							Ext.MessageBox.alert("系统提示", "导入成功");
						},
						failure: function(form, action) {
							var obj = JSON.parse(action.response.responseText);
							var res = obj.res;
							if (res == "1") {
								var result = obj.obj;
								var successCount = result.successCount;
								var errorCount = result.errorCount;
								var totalCount = successCount + errorCount;
								var batchId = result.batchId;
								var showMsg = "总计："
										+ totalCount
										+ "条;成功:"
										+ successCount
										+ "条;失败:"
										+ errorCount
										+ "条;";
								if (errorCount > 0) {
									Ext.MessageBox.confirm("提示", 
										showMsg + ",是否下载错误数据?",
										function(btn, txt) {
											if (btn == "yes") {
												//下载
												var downloadUrl = contextPath
														+ "/customer/import/download?batchId="
														+ batchId;
												location.href = downloadUrl;
											} else {
												console.log("canel")
											}
										}
									);
								} else {
									Ext.MessageBox.alert("提示", showMsg);
								}
							} else {
								Ext.MessageBox.alert("提示", "导入失败");
							}
						}
					});
				}
			}
		},{
			xtype : "button",
			text : "模板下载",
			iconCls : 'icon-save',
			handler : function() {
				location.href = customerTemplet;
			}
		}]
	});
	window.show();
}
